<template>
    <div class="back">
      <div class="home-header">
        <h3>饭了么</h3>
      </div>
      <h1>我的菜品</h1>

      <div class="commend-list">
      <template v-for="nestedArray in dishlist">
      <MyDishItem v-for="item in nestedArray" :item="item" :key="item.dishId"></MyDishItem>
    </template>
    </div>


      <van-tabbar route v-model="active" v-show="isNavbarVisible">
        <van-tabbar-item to="/mydish" icon="home-o">首页</van-tabbar-item>
        <van-tabbar-item to="/mine" icon="user-o">我的</van-tabbar-item>
      </van-tabbar>
    </div>
  </template>
  
  <script>
  import { mapState } from "vuex";
  //导入子组件·
  import MyDishItem from '@/components/MyDish.vue'
  import { getDishDate} from "@/api/shangjia/dish";
  export default {
    name: 'MyDish',
    data() {
      return {
        active: 0,
        dishlist: [],
        isNavbarVisible: true // 导航栏的显示状态
      }
    },
  components:{MyDishItem},
  computed: {
      ...mapState('user', ['userInfo'])
    },
  created() {
      this.getDishData();
      
    },
  methods:{
    getDishData() {
        getDishDate(this.userInfo.canteenWindowId).then((res) => {
        //  console.log(res);
          this.dishlist = [res.data.dishList];
          // console.log(this.dishlist);
        }).catch((err)=>{
          
        });
      },
      handleScroll() {
      const threshold = 100; // 滚动多少距离后隐藏导航栏，根据实际情况调整
      const scrollTop = window.scrollY;
      this.isNavbarVisible = scrollTop < threshold;
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll);
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.handleScroll);
  },
  }
  </script>

<style lang="less" scoped>

.back{
  background-color: #f7f8fa;
}
.home-header{
    width: 100%;
    height: 36px;
    background-color: rgb(10, 135, 245);
    position: fixed;
    top: 0;
    z-index: 1;
    h3{
        text-align: center;
        color: aliceblue;
    }
   
}
h1{
    margin-top: 50px;
   text-align: center;
}


</style>